      * cobc -x principal.cbl  estclientes.cbl -o estadisticas.exe
      ******************************************************************
       IDENTIFICATION DIVISION.
      ******************************************************************
       PROGRAM-ID. gestor_archivo.

      ******************************************************************
       ENVIRONMENT DIVISION.
      ******************************************************************
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
        SELECT ArchivoEntrada ASSIGN TO "ESTCLI.BIN"
        ORGANIZATION IS INDEXED
        ACCESS IS DYNAMIC
        RECORD KEY IS K-CLAVE
        FILE STATUS IS FS-ESTCLI.
      ******************************************************************
       DATA DIVISION.
      ******************************************************************
      *****************************************************
       FILE SECTION.
      *****************************************************
        FD ArchivoEntrada LABEL RECORD STANDARD.
        01 RegistroEntrada.
         03 K-CLAVE.
            05 COD-CLI      PIC 9(08).
			05 NRO-SEC      PIC 9(04).
         03 FEC-DESDE       PIC X(10).
         03 FEC-HASTA       PIC X(10).
         03 CATEG-HAB       PIC X(15).
         03 IMPORTE         PIC S9(06)V9(02).
      *****************************************************
       WORKING-STORAGE SECTION.
      *****************************************************
       01 FS-ESTCLI            PIC 9(2).

      *****************************************************
       LINKAGE SECTION.
      *****************************************************
       01 operacion         PIC X(01).
       01 registro.
         03 COD-CLI         PIC 9(08).
		 03 NRO-SEC         PIC 9(04).
         03 FEC-DESDE       PIC X(10).
         03 FEC-HASTA       PIC X(10).
         03 CATEG-HAB       PIC X(15).
         03 IMPORTE         PIC S9(06)V9(02).
       01 fs-clientes       PIC X(02).

      ******************************************************************
       PROCEDURE DIVISION USING operacion, registro, fs-clientes.
      ******************************************************************
         Inicio.
            EVALUATE operacion
              WHEN 'O' PERFORM open-clientes
              WHEN 'A' PERFORM open-io-clientes
              WHEN 'C' PERFORM close-clientes
			  WHEN 'S' PERFORM start-clientes
              WHEN 'R' PERFORM read-clientes
              WHEN 'N' PERFORM read-next-clientes
              WHEN 'W' PERFORM write-clientes
              WHEN 'U' PERFORM rewrite-clientes
              WHEN 'D' PERFORM delete-clientes
              WHEN other PERFORM oper-error
            END-EVALUATE.
      ******************************************************************
         open-clientes.
            OPEN INPUT ArchivoEntrada
            MOVE FS-ESTCLI TO fs-clientes
            GOBACK.
      ******************************************************************
         open-io-clientes.
            OPEN I-O ArchivoEntrada
            MOVE FS-ESTCLI TO fs-clientes
            GOBACK.
      ******************************************************************
         close-clientes.
            CLOSE ArchivoEntrada
            MOVE FS-ESTCLI TO fs-clientes
            GOBACK.
      ******************************************************************
	     start-clientes.
		    MOVE COD-CLI OF registro 
			  TO COD-CLI OF RegistroEntrada
			MOVE ZEROES              
			  TO NRO-SEC OF RegistroEntrada
            START ArchivoEntrada KEY IS GREATER K-CLAVE END-START
            MOVE FS-ESTCLI TO fs-clientes
            GOBACK.  			
      ******************************************************************
         read-clientes.
            MOVE COD-CLI OF registro
              TO COD-CLI OF RegistroEntrada
			MOVE NRO-SEC OF registro
			  TO NRO-SEC OF RegistroEntrada
            READ ArchivoEntrada END-READ
            MOVE FS-ESTCLI TO fs-clientes
            IF FS-ESTCLI = "00"
               PERFORM completar-registro
            END-IF
            GOBACK.
      ******************************************************************
         read-next-clientes.
            READ ArchivoEntrada NEXT RECORD END-READ
            MOVE FS-ESTCLI TO fs-clientes
      *			DISPLAY "File status read-next-clientes:"
      *			DISPLAY FS-ESTCLI
      *            DISPLAY COD-CLI   OF RegistroEntrada
      *            DISPLAY nro-sec   OF RegistroEntrada
      *            DISPLAY fec-desde OF RegistroEntrada
      *            DISPLAY fec-hasta OF RegistroEntrada
      *            DISPLAY CATEG-HAB OF RegistroEntrada
      *            DISPLAY importe   OF RegistroEntrada
            IF FS-ESTCLI = "00"
               PERFORM completar-registro
            END-IF
            GOBACK.
      ******************************************************************
         write-clientes.
           MOVE COD-CLI OF registro 
		     TO COD-CLI OF RegistroEntrada
		   MOVE NRO-SEC OF registro 
		     TO NRO-SEC OF RegistroEntrada
           READ ArchivoEntrada END-READ
           MOVE FS-ESTCLI TO fs-clientes
           IF FS-ESTCLI = "23"
              PERFORM completar-reg-Entrada
              WRITE RegistroEntrada END-WRITE
              MOVE FS-ESTCLI TO fs-clientes
           END-IF
           GOBACK.
      ******************************************************************
         rewrite-clientes.
           MOVE COD-CLI OF registro 
		     TO COD-CLI OF RegistroEntrada
		   MOVE NRO-SEC OF registro 
		     TO NRO-SEC OF RegistroEntrada
           READ ArchivoEntrada INTO RegistroEntrada END-READ
           MOVE FS-ESTCLI TO fs-clientes
           IF FS-ESTCLI = "00"
              PERFORM completar-reg-Entrada
              REWRITE RegistroEntrada END-REWRITE
              MOVE FS-ESTCLI TO fs-clientes
           END-IF
           GOBACK.
      ******************************************************************
         delete-clientes.
           MOVE COD-CLI OF registro 
		     TO COD-CLI OF RegistroEntrada
		   MOVE NRO-SEC OF registro 
		     TO NRO-SEC OF RegistroEntrada
           READ ArchivoEntrada INTO RegistroEntrada END-READ
           MOVE FS-ESTCLI TO fs-clientes
           IF FS-ESTCLI = "00"
              DELETE ArchivoEntrada END-DELETE
              MOVE FS-ESTCLI TO fs-clientes
           END-IF
           GOBACK.
      ******************************************************************
         oper-error.
           DISPLAY "Operacion desconocida".
           DISPLAY Operacion.
           GOBACK.
      ******************************************************************
          completar-registro.
            MOVE COD-CLI   OF RegistroEntrada
              TO COD-CLI   OF registro
            MOVE NRO-SEC   OF RegistroEntrada
              TO NRO-SEC   OF registro
            MOVE FEC-DESDE OF RegistroEntrada
              TO FEC-DESDE OF registro
            MOVE FEC-HASTA OF RegistroEntrada
              TO FEC-HASTA OF registro
            MOVE CATEG-HAB OF RegistroEntrada
              TO CATEG-HAB OF registro
            MOVE IMPORTE   OF RegistroEntrada
              TO IMPORTE   OF registro.
      ******************************************************************
          completar-reg-Entrada.
            MOVE COD-CLI   OF registro
              TO COD-CLI   OF RegistroEntrada
            MOVE NRO-SEC   OF registro
              TO NRO-SEC   OF RegistroEntrada
            MOVE FEC-DESDE OF registro
              TO FEC-DESDE OF RegistroEntrada
            MOVE FEC-HASTA OF registro
              TO FEC-HASTA OF RegistroEntrada
            MOVE CATEG-HAB OF registro
              TO CATEG-HAB OF RegistroEntrada
            MOVE IMPORTE   OF registro
              TO IMPORTE   OF RegistroEntrada.
